<template>
  <div>
    <el-row>
      <el-col :span="8">
        <!-- user卡片 -->
        <el-card v-model="userInfo">
          <el-button style="margin-left: 90%" type="text" @click="setUserInfoVisible = true">编辑</el-button>
          <div class="user">
<!--            <img-->
<!--                v-bind:src="userInfo.avatarPath === null ? 'http://s2xnpq3z5.hb-bkt.clouddn.com/%E5%A4%B4%E5%83%8F%20%E5%95%86%E5%8A%A1%E7%94%B7%E5%A3%AB.png':userInfo.avatarPath"-->
<!--                alt="">-->
            <img
                src="../assets/images/user-default.png"
                alt="">
            <div class="userInfo">
              <p class="name">姓名：{{ userInfo.chineseName }}</p>
              <p class="access">电话：{{ userInfo.mobile }}</p>
              <p class="access">邮箱：{{ userInfo.email }}</p>
            </div>
          </div>
          <div class="loginInfo">
<!--            <p>所属公司：<span>{{ userInfo.companyName }}</span></p>-->
<!--            <p>所属部门：<span>{{ userInfo.departmentName }}</span></p>-->
            <p>所属公司：<el-tag type="success" effect="light">{{ userInfo.companyName }}</el-tag></p>
            <p>所属部门：<el-tag type="warning" effect="light">{{ userInfo.departmentName }}</el-tag></p>
          </div>
        </el-card>
      </el-col>
      <el-col :span="16">
        <div class="num">
          <el-card v-for="item in CountData" :key="item.name" :body-style="{ display: 'flex', padding: 0 }">
            <i class="icon" :class="`el-icon-${item.icon}`" :style="{ backgroundColor: item.color }"></i>
            <div class="details">
              <p class="price">{{ priceFormate(item.value) }}</p>
              <p class="desc">{{ item.name }}</p>
            </div>
          </el-card>
        </div>
      </el-col>
    </el-row>
    <el-dialog
        title="提示"
        :visible.sync="setUserInfoVisible"
        width="30%"
        :before-close="handleClose">
      <el-form ref="UserVisible" :model="UserVisible" label-width="80px">
        <el-form-item label="姓名">
          <el-input v-model="UserVisible.name">{{userInfo.name}}</el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
    <el-button @click="setUserInfoVisible = false">取 消</el-button>
    <el-button type="primary" @click="setUserInfoVisible = false">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import TableLabel from '../data/TableLabel'
import CountData from '../data/CountData'
import {getData} from '../api/index'

// echarts的配置数据
import order from '../data/echartsData/order'
import user from '../data/echartsData/user'
import video from '../data/echartsData/video'

export default {
  data() {
    return {
      TableData: [],
      TableLabel,
      CountData,
      userInfo: JSON.parse(localStorage.getItem('userInfo')),
      setUserInfoVisible: false,
      UserVisible:JSON.parse(localStorage.getItem('userInfo'))
    }
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
    },
    priceFormate(price) {
      // return "￥" + price
      return price
    }
  },
  mounted() {
    getData().then((data) => {
      // console.log(data);
      this.TableData = data.data.getStatisticalData.data.tableData

      // echarts图表

      // 折线图

      // 基于准备好的dom，初始化echarts实例
      // const echarts1 = echarts.init(this.$refs.echarts1)
      var echarts1Option = order
      // ES6解构语法
      var {orderData, userData, videoData} = data.data.getStatisticalData.data

      // 获取x轴:要求是一个对象
      const xAxis = Object.keys(orderData.data[0])
      const xAxisData = {
        data: xAxis
      }

      // 配置
      echarts1Option.legend = xAxisData
      echarts1Option.xAxis = xAxisData
      echarts1Option.yAxis = {}
      echarts1Option.series = []

      // 配置series
      xAxis.forEach(key => {
        echarts1Option.series.push({
          name: key,
          type: 'line',
          // key对应的orderData的所有值
          data: orderData.data.map(item => item[key])
        })
      })

      // 使用刚指定的配置项和数据显示图表。
      // echarts1.setOption(echarts1Option);

      // 柱状图
      // const echarts2 = echarts.init(this.$refs.echarts2)
      var echarts2Option = user

      // 配置
      echarts2Option.xAxis.data = userData.map(item => item.date)
      echarts2Option.series = [
        {
          name: '新增用户',
          data: userData.map(item => item.new),
          // 类型:bar是柱状图
          type: 'bar'
        }
        ,
        {
          name: '活跃用户',
          data: userData.map(item => item.active),
          type: 'bar'
        }
      ]

      // echarts2.setOption(echarts2Option);

      // 饼状图
      // const echarts3 = echarts.init(this.$refs.echarts3)
      var echarts3Option = video
      echarts3Option.series = {
        data: videoData,
        type: 'pie'
      }
      // echarts3.setOption(echarts3Option);
    })
  }
}
</script>

<style lang="less" scoped>
.user {
  // 垂直居中
  display: flex;
  align-items: center;

  // 外边距:分割线距离loginInfo的距离
  margin-bottom: 20px;
  // 内边距:分割线距离User的距离
  padding-bottom: 20px;
  border-bottom: 1px solid #ccc;

  img {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    margin-right: 40px;
  }

  .userInfo {
    .name {
      font-size: 32px;
      margin-bottom: 10px;
    }

    .access {
      color: #999999;
    }
  }
}

.loginInfo {
  p {
    line-height: 28px;
    font-size: 14px;
    color: #999999;

    span {
      color: #666666;
      margin-left: 60px;
    }
  }
}

.num {
  display: flex;
  // 要换行
  flex-wrap: wrap;
  // 从头到尾均匀排列
  justify-content: space-between;
  margin-left: 20px;

  .el-card {
    width: 32%;
    margin-bottom: 20px;

    .icon {
      width: 80px;
      height: 80px;
      line-height: 80px;
      text-align: center;
      font-size: 30px;
      color: #fff;
    }

    .details {
      // 竖着排且居中
      display: flex;
      flex-direction: column;
      justify-content: center;

      margin-left: 15px;

      .price {
        font-size: 30px;
        margin-bottom: 10px;
        line-height: 30px;
        height: 30px;
      }

      .desc {
        font-size: 14px;
        color: #999;
        text-align: center;
      }
    }
  }
}

.graph {
  display: flex;
  // 两个靠边
  justify-content: space-between;
  margin-top: 20px;

  .el-card {
    width: 49%;
  }
}
</style>
